﻿@model IList<UserToken>
@using NewLife.Cube.Entity
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using XCode.Membership;
@using NewLife.Cube;
@{
    var fact = ViewBag.Factory as IEntityFactory;
    var page = ViewBag.Page as Pager;
    var set = ViewBag.PageSetting as PageSetting ?? PageSetting.Global;
    var provider = ManageProvider.Provider;
}
<table class="table table-hover">
    <thead>
        <tr>
            @if (set.EnableSelect)
            {
                <th class="text-center" style="width:10px;">
                    <label class="checkbox checkbox-single">
                        <input type="checkbox" id="chkAll" title="全选" />
                        <span></span>
                    </label>
                </th>
            }
            <th><a href="@Html.Raw(page.GetSortUrl("Token"))">令牌</a></th>
            <th title="地址。锁定该令牌只能访问该资源路径"><a href="@Html.Raw(page.GetSortUrl("Url"))">地址</a></th>
            <th class="text-center">页面</th>
            <th class="text-center">Json数据</th>
            <th class="text-center">Xml数据</th>
            <th class="text-center">Csv数据</th>
            <th class="text-center" title="用户。本地用户"><a href="@Html.Raw(page.GetSortUrl("UserID"))">用户</a></th>
            <th class="text-center" style="min-width:134px;"><a href="@Html.Raw(page.GetSortUrl("Expire"))">过期时间</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Enable"))">启用</a></th>
            <th class="text-center" title="次数。该令牌使用次数"><a href="@Html.Raw(page.GetSortUrl("Times"))">次数</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("LastIP"))">最后地址</a></th>
            <th class="text-center" style="min-width:134px;"><a href="@Html.Raw(page.GetSortUrl("LastTime"))">最后时间</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("UpdateIP"))">更新地址</a></th>
            <th class="text-center" style="min-width:134px;"><a href="@Html.Raw(page.GetSortUrl("UpdateTime"))">更新时间</a></th>
            @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
            {
                <th class="text-center">操作</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var entity in Model)
        {
            var url = entity.Url + "";
            var query = "";
            var p = url.IndexOf('?');
            if (p >= 0)
            {
                query = url.Substring(p);
                url = url.Substring(0, p);
            }
            if (!query.IsNullOrEmpty())
                query += "&token=" + entity.Token;
            else
                query += "?token=" + entity.Token;

        <tr>
            @if (set.EnableSelect)
            {
                <td class="text-center align-middle pt-0 pb-0">
                    <label class="checkbox checkbox-single">
                        <input class="checkable" type="checkbox" name="keys" value="@entity.ID" />
                        <span></span>
                    </label>
                </td>
            }
            <td>@entity.Token</td>
            <td style="max-width:400px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" title="@entity.Url">@entity.Url</td>
            <td class="text-center"><a href="@(url+"/Html"+query)" target="_blank">页面</a></td>
            <td class="text-center"><a href="@(url+"/Json"+query)" target="_blank">Json数据</a></td>
            <td class="text-center"><a href="@(url+"/Xml"+query)" target="_blank">Xml数据</a></td>
            <td class="text-center"><a href="@(url+"/Csv"+query)" target="_blank">Csv数据</a></td>
            <td class="text-center">@entity.UserName</td>
            <td class="text-center">@entity.Expire.ToFullString("")</td>
            <td class="text-center">
                <i class="glyphicon glyphicon-@(entity.Enable ? "ok" : "remove")" style="color: @(entity.Enable ? "green" : "red");"></i>
            </td>
            <td class="text-right">@entity.Times.ToString("n0")</td>
            <td>@entity.LastIP</td>
            <td class="text-center">@entity.LastTime.ToFullString("")</td>
            <td class="text-center">@provider.FindByID(entity.UpdateUserID)</td>
            <td class="text-center" title="@entity.UpdateIP.IPToAddress()">@entity.UpdateIP</td>
            @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
            {
                <td class="text-center">
                    @await Html.PartialAsync("_List_Data_Action", (Object)entity)
                </td>
            }
        </tr>
        }
    </tbody>
</table>